#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[N];
int mn[N << 2];
void pushup(int p) { mn[p] = min(mn[p << 1], mn[p << 1 | 1]); }
void build(int p, int l, int r) {
  if (l == r) {
    mn[p] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
int query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return mn[p];
  int res = 1e9;
  int mid = (l + r) >> 1;
  if (L <= mid) res = min(res, query(L, R, p << 1, l, mid));
  if (R > mid) res = min(res, query(L, R, p << 1 | 1, mid + 1, r));
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  build(1, 1, n);
  while (m--) {
    int L, R;
    cin >> L >> R;
    if (L > R) swap(L, R);
    cout << query(L, R, 1, 1, n) << ' ';
  }

  return 0;
}